﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Coronox.SkyShell;
using System.Threading.Tasks;
using GalaSoft.MvvmLight.Threading;

namespace SkyShell.ViewModel
{
    public class StopSyncViewModel : ViewModelBase
    {
        public StopSyncViewModel()
        {
            //cut and paste this line to your ctor
            _detach = new RelayCommand(ExecDetach, CanDetach);
            //cut and paste this line to your ctor
            _delete = new RelayCommand(ExecDelete, CanDelete);
        }


        private RelayCommand _detach;
        public RelayCommand Detach
        {
            get
            {
                return _detach;
            }
        }

        /// <summary>
        /// Checks whether the Detach command is executable
        /// </summary>
        private bool CanDetach()
        {
            return true;
        }

        /// <summary>
        /// Executes the Detach command 
        /// </summary>
        private void ExecDetach()
        {

            App.Current.MainWindow.Hide();
            Task t = new Task(() =>
             {
                 Sky.StopSyncFolder(Environment.GetCommandLineArgs()[2], StopSyncOption.Detach);

                 DispatcherHelper.CheckBeginInvokeOnUI(() => App.Current.Shutdown());
             });
            t.Start();
        }


        private RelayCommand _delete;
        public RelayCommand Delete
        {
            get
            {
                return _delete;
            }
        }

        /// <summary>
        /// Checks whether the Delete command is executable
        /// </summary>
        private bool CanDelete()
        {
            return true;
        }

        /// <summary>
        /// Executes the Delete command 
        /// </summary>
        private void ExecDelete()
        {
            App.Current.MainWindow.Hide();

            Task t = new Task(() =>
                {
                    Sky.StopSyncFolder(Environment.GetCommandLineArgs()[2], StopSyncOption.Delete);
                    DispatcherHelper.CheckBeginInvokeOnUI(()=>App.Current.Shutdown());
                });
            t.Start();

        }




    }
}
